<script setup lang="ts">
import { ref, reactive, h } from "vue";
import { getAwaitReceiveListApi, receiveApi } from "/@/api/mes/feedback";
import { useModal } from '/@/hooks/useModal'
import { useTableNotCheck, useDeleteSucessMessage, useConfirm, useSuccessMessage } from '/@/hooks/useMessage'

// 表格配置
const tableRef = ref<YTableInstance>();
const tableProps = reactive<YTableProps>({
  height: "auto",
  columns: [
    { field: "workOrderCode", label: "工单编号", width: 150 },
    { field: "productName", label: "产品名称", width: 100 },
    { field: "productCode", label: "产品编号", width: 100 },
    { field: "processName", label: "工序", width: 100 },
    { field: "planWorkingTime", label: "计划工时", width: 100 },
    { field: "planStartTime", label: "计划开始", width: 100, formatter: 'date' },
    { field: "planEndTime", label: "计划结束", width: 100, formatter: 'date' },
    { field: "planQuantity", label: "数量", width: 100 },

  ],
  remoteConfig: {
    api: getAwaitReceiveListApi,
    immediate: true
  },
  filters: [
    {
      label: '工序', field: 'processId', component: {
        key: 'SelectMaker',
        props: {
          dataSource: 'Process',
          hasAll: true
        }
      }
    },
    { label: '工单编号', field: 'keyword1' },
    { label: '产品编号/名称', field: 'keyword2' },
  ],
  operas: [
    {
      title: '接收',
      type: 'primary',
      onClick: async () => {
        const selects = await tableRef.value.getCheckRecords(true);

        await receiveApi({
          ids: selects.map(s => s.id)
        })
        useSuccessMessage('接收成功')
        // viewModal.open({ contentProps: { id: select.id } })
      }
    },
  ]
});

// 编辑窗口
const isChange = ref(false)
const viewModal = useModal({
  title: '接收',
  width: 380,
  height: 300,
  content: () => import('./receive.vue'),
  contentOn: {
    onChange: () => {
      isChange.value = true
    }
  }
});

viewModal.on('open', () => {
  isChange.value = false
})
viewModal.on('close', () => {
  if (isChange.value) {
    tableRef.value.loadData()
  }
})

</script>
<template>
  <IndexLayout>
    <YTable v-bind="tableProps" ref="tableRef"></YTable>
  </IndexLayout>
</template>